<?php
/*
if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
	header('Allow: POST');
	header('HTTP/1.1 405 Method Not Allowed');
	header('Content-Type: text/plain');
	exit;
}*/

/** Sets up the WordPress Environment. */
require( dirname(__FILE__) . '/wp-load.php' );

nocache_headers();

echo('<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
echo('<style>td{font-size:12px;} th{background-color:#4f81bd;color:#fff;font-size:12px;} caption{font-size:16px;font-weight:bold;}</style></head>');
echo('<body>');

$cnt = $wpdb->get_row("select count(*) as sum from wp_player");
echo('<table><caption>选手名单（共' . $cnt->sum . '人）</caption>');
echo('<tr><th width="60">姓名</th><th width="60">英文名</th><th width="28">性别</th><th width="68">生日</th>');
echo('<th width="40">省份</th><th width="40">城市</th>');
echo('<th width="100">学校</th><th width="100">地址</th><th width="50">邮编</th><th width="54">父母姓名</th>');
echo('<th width="60">电话</th><th width="120">身份证号码</th>');
echo('<th width="100">Email</th><th width="52">组别</th><th width="60">参选号</th><th width="68">注册时间</th>');

$sql = "select p.name, p.eng_name, IF(p.sex = 1, '男', '女') as sex, p.birthday, " .
            "prov.region_name as province, city.region_name as city, p.school, p.post, p.postcode, " . 
            "p.parent_name, p.phone, p.idcard, p.email, p.teacher, p.hobby, g.group_name, p.player_sn, p.reg_time " .
        "from wp_player p, wp_region prov, wp_region city, wp_player_group g " . 
        "where p.region_id = city.region_id and city.parent_id = prov.region_id and p.group_id = g.ID " .
        "order by p.ID";
$players = $wpdb->get_results($sql);
$i = 0;
foreach($players as $p) {
    if ($i % 2 == 0) {
        echo('<tr style="background-color:#d8d8d8;">');
    } else {
        echo('<tr>');
    }
    echo("<td>" . $p->name . "</td><td>" . $p->eng_name . "</td><td>" . $p->sex . "</td><td>" . date('Y-m-d', $p->birthday) . "</td>");
    echo("<td>" . $p->province . "</td><td>" . $p->city . "</td><td>" . $p->school . "</td><td>" . $p->post . "</td>");
    echo("<td>" . $p->postcode . "</td><td>" . $p->parent_name . "</td><td>" . $p->phone . "</td><td>" . $p->idcard . "</td>");
    echo("<td>" . $p->email . "</td><td>" . $p->group_name . "</td><td>" . $p->player_sn . "</td><td>" . date('Y-m-d', $p->reg_time) . "</td>");
    echo("</tr>");
    $i++;
}
echo("</table>");
echo('</body>');
?>
